package cn.ubeta.ar.utils;

/**
 * Created by fengyijun on 2016/12/19.
 */
import android.content.Context;
import android.graphics.Rect;
import android.graphics.RectF;

public class DisplayUtil {
	private static final String TAG = "DisplayUtil";

	public static RectF getUIRect(Rect faceRect,int w_screen,int h_screen,int w_preview,int h_preview) {
		float x_scale = w_screen*1.0f/h_preview;
		float y_scale = h_screen*1.0f/w_preview;
//		Log.i(TAG,"w_screen="+w_screen+" h_screen="+h_screen+" w_preview"+w_preview+" h_preview"+h_preview);
//		Log.i(TAG,"x_scale= "+x_scale+"y_scale="+y_scale);
		return new RectF(faceRect.left*x_scale,faceRect.top*y_scale,faceRect.right*x_scale,faceRect.bottom*y_scale);
	}

	public static int dip2px(Context context, float dipValue){
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int)(dipValue * scale + 0.5f);
	}

	/**
	 * pxתdip
	 * @param context
	 * @param pxValue
	 * @return
	 */
	public static int px2dip(Context context, float pxValue){
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int)(pxValue / scale + 0.5f);
	}

	public static int getScreenWidth(Context context) {
		return context.getResources().getDisplayMetrics().widthPixels;
	}

	public static int getScreenHeight(Context context) {
		return context.getResources().getDisplayMetrics().heightPixels;
	}
}
